﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Media;
using System.Windows.Shapes;

namespace WpfApp2_DockPanel.Model
{
    class ColorBox : ListBox
    {
        string[] strColors =
        {
            "Black", "Brown", "DarkGreen", "MidnightBlue", "Navy",
            "DarkBlue", "Indigo", "DimGray", "DarkRed", "OrangeRed", "Olive", "Green",
            "Teal", "Blue", "SlateGray", "Gray", "Red", "Orange", "YellowGreen",
            "SeaGreen", "Aqua", "LightBlue", "Violet", "DarkGray", "Pink", "Gold",
            "Yellow", "Lime", "Turquoise", "SkyBlue", "Plum", "LightGray", "LightPink",
            "Tan", "LightYellow", "LightGreen", "LightCyan", "LightSkyBlue", "Lavender",
            "White"
        };

        public ColorBox()
        {
            FrameworkElementFactory factoryUnigrid = new FrameworkElementFactory(typeof(UniformGrid));
            factoryUnigrid.SetValue(UniformGrid.ColumnsProperty, 8);
            ItemsPanel = new ItemsPanelTemplate(factoryUnigrid);
            foreach(string strColor in strColors)
            {
                Rectangle rect = new Rectangle();
                rect.Width = 12;
                rect.Height = 12;
                rect.Margin = new Thickness(4);
                rect.Fill = typeof(Brushes).GetProperty(strColor).GetValue(null, null) as Brush;

                ToolTip tip = new ToolTip();
                tip.Content = strColor;
                rect.ToolTip = tip;

                Items.Add(rect);

            }

            SelectedValuePath = "Fill";
        }
    }
}
